import {ChangeDetectorRef, Component, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {ActivatedRoute, ParamMap, Router} from '@angular/router';
import 'rxjs/add/operator/switchMap';
import {AppUrl} from '../../../app.url';
import {HttpClient} from '@angular/common/http';

@Component({
    selector: 'app-school-detail',
    templateUrl: './school-detail.component.html',
    styleUrls: ['./school-detail.component.less'],
})
export class SchoolDetailComponent implements OnInit {

    area: any = [];
    schoolList = {
        name: '暨南大学',
        count: '111',
    };
    campList = [];
    actList = [];
    campLastActList = [{
        campId: '',
        campTotalAct: '',
        campTotalActMoney: '',
        lastAct: {
            activityId: '',
            activityDetail: '',
            activityName: '',
        }
    }];
    cityList = ['全部', '广州', '韶关', '深圳', '珠海', '汕头', '佛山', '江门', '湛江', '茂名', '肇庆',
        '惠州', '梅州', '汕尾', '河源', '阳江', '清远', '东莞', '中山', '潮州', '揭阳', '云浮'];
    actbList = [{
        name: '暨南大学创新创业联赛',
        author: '赵四',
        price: '￥200000',
    }];
    slides = [
        {
            image: 'assets/img/coffee1.jpg',
        },
        {
            image: 'assets/img/coffee1.jpg',
        },
        {
            image: 'assets/img/coffee1.jpg',
        },
        {
            image: 'assets/img/coffee1.jpg',
        }
    ];

    constructor(private http: HttpClient, private route: ActivatedRoute, private router: Router, private ref:ChangeDetectorRef) {
        this.univId = this.route.snapshot.paramMap.get('uniId');
        this.http.post(AppUrl.univeristy.selectByIdUrl, {univId: this.univId}).subscribe(data => {
            console.log(data);
            let temp: any = data;
            // this.provList = temp.data;
            this.schoolList.name = temp.data.univName;
            this.schoolList.count = temp.data.campTotalNum;
        });

        let univTmp: number = this.univId;
        this.http.post(AppUrl.place.areaUrl, {universityid: univTmp}).subscribe(data => {

            let temp: any = data;
            console.log(temp.data);
            this.area = temp.data;
        });

        this.http.post(AppUrl.campus.campDetByUnivID, {
            pageNo: 1,
            pageSize: this.page.pageSize,
            univId: this.univId,
            areaId: -1
        }).subscribe(data => {
                let temp: any = data;
                this.page = temp.data;
                this.campList = temp.data.list;
                this.campLastActList = [];

                // for( let lst of this.campList) {
                //     this.http.post(AppUrl.activity.selectLastActByCampId, {campId:lst.campId}).subscribe(data => {
                //         if(!data) {
                //             let temp: any = data;
                //             this.page = temp.data;
                //             // this.actList = temp.data.list;
                //             this.campLastActList.push({
                //                 campId: lst.campId,
                //                 campTotalAct: lst.campTotalAct,
                //                 campTotalActMoney: lst.campTotalActMoney,
                //                 lastAct: {
                //                     activityId: this.page.list.activityId,
                //                     activityDetail: this.page.list.activityDetail,
                //                     activityName: this.page.list.activityName
                //                 },
                //             });
                //         }
                //         else{
                //             this.campLastActList.push({
                //                 campId: lst.campId,
                //                 campTotalAct: lst.campTotalAct,
                //                 campTotalActMoney: lst.campTotalActMoney,
                //                 lastAct: {
                //                     activityId: '',
                //                     activityDetail: '',
                //                     activityName: ''
                //                 },
                //             });
                //         }
                //     });
                // }
            }
        );
    }

    private page: any = {
        pageNum: 1,
        pageSize: 12,
        total: 0,
    };
    areaId: number;

    areaFiliter(areaId) {
        this.areaId = areaId;
        this.search(1);
    }

    search(pageNum) {
        this.http.post(AppUrl.campus.campDetByUnivID, {
            pageNo: pageNum,
            pageSize: this.page.pageSize,
            univId: this.univId,
            areaId: this.areaId
        }).subscribe(data => {
            let temp: any = data;
            this.page = temp.data;
            this.campList = temp.data.list;
        });
    }

    univId;

    ngOnInit() {


        // console.log(id);

        // this.uniId = this.route.paramMap
        //     .switchMap((params: ParamMap) =>
        //         this.service.getHero(params.get('uniId')));
    }

}
